# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=zarn
pkgver=0.0.9.r86.g2185620
pkgrel=1
pkgdesc='A lightweight static security analysis tool for modern Perl Apps.'
arch=('any')
groups=('blackarch' 'blackarch-code-audit')
url='https://github.com/htrgouvea/zarn'
license=('MIT')
depends=('perl' 'perl-file-find-rule' 'perl-getopt-long' 'perl-json'
         'perl-ppi' 'perl-yaml-tiny')
makedepends=('git')
source=("git+https://github.com/htrgouvea/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/"{bin,share/$pkgname}
  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" *.md

  install -Dm 644 LICENSE.md "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  rm -rf *.md .gitignore .github

  cp -a * "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec perl ./zarn.pl "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

